﻿using Microsoft.Practices.Prism.ViewModel;
using System;
using System.Collections.Generic;
using System.Windows;

namespace FBA.Client.Models
{
    public partial class ReportVariable : NotificationObject
    {
        private string _name;

        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
            }
        }

        private string _variable;

        public string Variable
        {
            get { return _variable; }
            set
            {
                _variable = value;
            }
        }

        private string _inputType;

        public string InputType
        {
            get { return _inputType; }
            set
            {
                _inputType = value;
            }
        }


        private Dictionary<string, string> _inputDictionary;

        public Dictionary<string, string> InputDictionary
        {
            get { return _inputDictionary; }
            set
            {
                _inputDictionary = value;
            }
        }

        private string[] _inputEnum;

        public string[] InputEnum
        {
            get { return _inputEnum; }
            set
            {
                _inputEnum = value;
            }
        }
        

        private string _defaultValue;

        public string DefaultValue
        {
            get { return _defaultValue; }
            set
            {
                _defaultValue = value;
            }
        }

        private bool _isDisplay;

        public bool IsDisplay
        {
            get { return _isDisplay; }
            set
            {
                _isDisplay = value;
            }
        }

        private bool _isEditable;

        public bool IsEditable
        {
            get { return _isEditable; }
            set
            {
                _isEditable = value;
            }
        }

        private bool _isRequire;

        public bool IsRequire
        {
            get { return _isRequire; }
            set
            {
                _isRequire = value;
            }
        }



        private string _value;

        public string Value
        {
            get { return _value; }
            set
            {
                if (this.IsRequire)
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        MessageBox.Show(this.Name + " is require");
                        return;
                    }
                }

                if (this.InputType.Equals("Date"))
                {
                    try
                    {
                        DateTime dt = DateTime.ParseExact(value, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                        value = dt.ToString("yyyy-MM-dd");
                    }
                    catch(Exception)
                    {
                        MessageBox.Show(this.Name + " is invalid");
                        return;
                    }
                }
                else if (this.InputType.Equals("Dictionary"))
                {

                }
                else if (this.InputType.Equals("In"))
                {
                    
                }
                else if (this.InputType.Equals("Number"))
                {
                    int result;
                    if (!string.IsNullOrEmpty(value) && !int.TryParse(value, out result))
                    {
                        MessageBox.Show(this.Name + " is invalid");
                        return;
                    }
                }
                else if (this.InputType.Equals("Text"))
                {

                }

                _value = value;
                this.RaisePropertyChanged("Value");
            }
        }



    }
}
